import request from '@/utils/request';


export interface TenderInfo {
  tenderInfoId: number| null;
  purchasePlanId: number| null;
  announcement: string| null;
  deadline: string| null;
  bidSupplierName: string| null;
  bidPrice: number| null;
  contractUrl: string| null;
  status: number| null;
}

export interface Tender {
  tenderName: string | null;
  tenderPrice: number | null;
}

export interface TenderInfoFormItemConfig {
  type: 'input' | 'datetime' | 'select' | 'textarea';
  label: string;
  prop: keyof TenderInfo;
  placeholder?: string;
  inputType?: HTMLInputElement['type'];
  options?: Array<{label: string, value: any}>;
}

export interface TenderInfoModel {
  profileId: number | null;
  tenderInfoId: number | null;
  purchasePlanId: number | null;
  announcement: string | null;
  deadline: string | null;
  bidSupplierName: string | null;
  bidPrice: number | null;
  contractUrl: string | null;
  status: number | null;
}

export interface TenderFormItemConfig {
  type: 'input' | 'datetime' | 'select';
  label: string;
  prop: keyof Tender;
  placeholder?: string;
  inputType?: HTMLInputElement['type'];
  options?: Array<{label: string, value: any}>;
}



export const monitorApi = {
  getPurchasePlanStatus: (planId: number) => {
    return request<number>({
      method: 'GET',
      url: `/procedure/monitor/purchasePlanStatus`,
      params: { planId: planId }
    });
  },

  updatePurchasePlanStatus: (planId: number, status: number) => {
    return request<String>({
      method: 'PATCH',
      url: `/procedure/monitor/purchasePlanStatus/${planId}`,
      params: { status: status }
    });
  },

  getTenderInfo: (planId: number) => {
    return request<TenderInfo>({
      method: 'GET',
      url: `/procedure/monitor/tender`,
      params: { planId: planId }
    });
  },

  saveOrUpdateTender: (data: TenderInfoModel) => {
    return request<String>({
      method: 'POST',
      url: `/procedure/monitor/tender`,
      data: data
    });
  },

  listAllBids: () => {
    return request<Tender[]>({
      method: 'GET',
      url: `/procedure/monitor/bids`
    });
  },

  confirmBid: (planId: number, supplierName: string, bidPrice: number) => {
    return request<string>({
      method: 'POST',
      url: `/procedure/monitor/confirmBid/${planId}`,
      params: { 
        supplierName: supplierName,
        bidPrice: bidPrice
      }
    });
  },

  uploadContractFile: (file: File) => {
    const formData = new FormData();
    formData.append('file', file);
    return request<string>({
      method: 'POST',
      url: `/procedure/monitor/contract/uploadFile`,
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    });
  },

  saveContract: (planId: number, contractUrl: string) => {
    return request<string>({
      method: 'POST',
      url: `/procedure/monitor/contract/${planId}`,
      params: { contractUrl: contractUrl }
    });
  },

  deviceArrival: (planId: number, purchaseDate: string) => {
    return request<string>({
      method: 'POST',
      url: `/procedure/deviceArrival/${planId}`,
      params: { purchaseDate: purchaseDate }
    });
  },
};